import app from '@/config/eth_app';
export default ({ $web3 }) => {
  const { abi, usdtContractAddr, spxContractAddr} = app;
  return {
    // 授权 Usdt
    async approveUsdt(amountUsd) {
      const amountUsdWei = $web3.utils.parseEther(amountUsd.toString());
      const usdtTc = await $web3.getSingerContract(usdtContractAddr, abi);
      const tr = await usdtTc.approve(spxContractAddr, amountUsdWei);
      await tr.wait();
    },

    // 购买 employer 或者 nomad 身份
    async mintNft_(mint) {
      const tc = await $web3.getSingerContract(spxContractAddr, abi);
      return await tc.mintNft(mint);
    },

    // 发布任务合约支付
    async publish_(nomad, amount, stage, random) {
      const amountUsdWei = $web3.utils.parseEther(amount.toString());
      const tc = await $web3.getSingerContract(spxContractAddr, abi);
      return await tc.publish(nomad, amountUsdWei, stage, random);
    },
    // 任务完成交付
    async dislodge_(random) {
      const tc = await $web3.getSingerContract(roraContractAddr, abi);
      return await tc.dislodge(random);
    },

  };
};
